package logic

import (
	"context"
	"errors"
	"furni-mgr/furnirpc/furnirpc"
	"furni-mgr/furnirpc/internal/svc"
	"furni-mgr/models/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type FurnitureShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewFurnitureShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FurnitureShowLogic {
	return &FurnitureShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 家具详情方法
func (l *FurnitureShowLogic) FurnitureShow(in *furnirpc.FurnitureShowRequest) (*furnirpc.FurnitureShowResponse, error) {
	// todo: add your logic here and delete this line
	var furniture mysql.ShowFurniture

	furniture, err := mysql.FurnitureShow(mysql.DB, in.FurnitureId)
	if err != nil {
		return nil, errors.New("该家具不存在")
	}

	return &furnirpc.FurnitureShowResponse{
		FurnitureId:    int64(furniture.ID),
		FurnitureName:  furniture.FurnitureName,
		FurniturePrice: float32(furniture.FurniturePrice),
		BrandName:      furniture.BrandName,
		ClassName:      furniture.ClassName,
	}, nil
}
